import Vue from 'vue';

let DongxwDict = {

    store: {

        CLASS_TYPES: [[10, '10-- 正常班 '], [20, '20-- 加班  '], [30, '30-- 休班 ']],
        SUBCLASS_TYPES: [[10, '10--正常班'], [20, '20--自动算'], [21, '21--平时加班'], [22, '22--周末加班'], [23, '23--节日加班'], [30, '30--出差'], [31, '31--请假'], [32, '32--调休'], [33, '33-休假'], [34, '34--事假'], [35, '35--病假']],
        OVERTIMES_TYPES: [[20, '20--自动算'], [21, '21--平时加班'], [22, '22--周末加班'], [23, '23--节假日加班']],
        HOLIDAYS_TYPES: [[30, '30--出差'], [31, '31--请假'], [32, '32--调休'], [33, '33-休假'], [34, '34--事假'], [35, '35--病假']],

        // STATUS: [[1, '启用'], [0, '禁用']],
        STATUS: [[0, '草稿'], [1, '启用'], [2, '禁用']],

        PERIOD_TYPES: [[0, '考勤'], [100, '工资周期']],
        DAY_TYPES: [[10, '节假日'], [20, '工作日']],

        TAX_INCLUDE: [[1, '含税'], [0, '不含税']],
        YESNO_TYPE: [[1, '是'], [0, '否']],
        WH_NAME: [[10, '原料成品库'], [30, '外购成品库']],
        SUPPLY_TYPES: [[0, '原料供应商'], [1, '产品供应商'], [2, '产品与原料供应商']],
        LANGUAGE_TYPE: [[100, '中文'], [200, '英文']],
        MONEY_TYPE: [[100, 'CNY'], [200, '美元'], [300, '港币']],

        ISSUE_PRD_TYPE: [[30, '送货单'], [31, '退货单']],

        LOSS_TYPE: [[1, '损耗率(%)'], [0, '损耗数']],

        OUT_FLAG: [[1, '外发'], [0, '生产']],
        FINISH_FLAG: [[1, '完成'], [0, '未完成']],
        AUDIT_STATUS: [[0, '草稿'], [10, '提交审核'], [20, '审核通过'], [30, '审核不通过']],
        PLAN_STATUS: [[0, '草稿'], [10, '进行中'], [20, '完成'], [30, '取消']],
        ORDER_STATUS: [[0, '草稿'], [10, '下单'], [20, '生产中'], [30, '生产完成'], [40, '发货完成'], [50, '收款完成'], [100, '取消'], [101, '作废']],

        ORDER_TYPE: [[0, '普通订单'], [100, '父订单'], [200, '子订单']],
        RM_TYPE: [[100, '主料'], [200, '辅料'], [300, '包装材料'], [400, '部件']],
        STORE_TYPE: [[200, '原材料'], [100, '半成品']]

    },
    getEntry: function (key, storeArr) {
        let arr = storeArr || [];
        return arr.find((entry) => entry[0] === key);
    },
    getText: function (key, storeArr) {
        let tmp = this.getEntry(key, storeArr);
        return tmp ? tmp[1] : '-';
    },
    viewDate: function (d) {
        if (typeof (d) === 'string') {
            //  d = DongxwDict.formatDatetime(d)
        } else {
            var date = new Date();
            date.setTime(d);
            return DongxwDict.formatDate(date)
        }
        return d ? d.substr(0, 10) : '-';
    },
    viewDatetime: function (d) {
        if (typeof (d) === 'string') {
            //  d = DongxwDict.formatDatetime(d)
        } else {
            var date = new Date();
            date.setTime(d);
            return DongxwDict.formatDatetime(date)
        }
        return d ? d : '-';
    },
    formatDatetime: function (now) {
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        var hour = now.getHours();
        var minute = now.getMinutes();
        var second = now.getSeconds();
        return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second;
    },

    formatDate: function (now) {
        var year = now.getFullYear();
        var month = (now.getMonth() + 1 + 100) % 100;
        var date = (now.getDate() + 100) % 100;
        return year + '-' + month + '-' + date;
    },
    formatDateZero: function (now) {
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        var date = now.getDate();
        return year + '-' + month + '-' + date + ' 00:00:00';
    },
    formatDateYm: function (now) {
        var year = now.getFullYear();
        var month = now.getMonth() + 1;
        // var date = now.getDate();
        return year * 100 + month;
    },

    // 去掉左边的空白
    trimLeft: function (s) {
        if (s == null) {
            return ''
        }
        var whitespace = String(' \t\n\r');
        var str = String(s);
        if (whitespace.indexOf(str.charAt(0)) !== -1) {
            let j = 0
            let i = str.length
            while (j < i && whitespace.indexOf(str.charAt(j)) !== -1) {
                j++;
            }
            str = str.substring(j, i);
        }
        return str;
    },

    // 去掉右边的空白 www.2cto.com
    trimRight: function (s) {
        if (s == null) return '';
        var whitespace = String(' \t\n\r')
        var str = String(s);
        if (whitespace.indexOf(str.charAt(str.length - 1)) !== -1) {
            var i = str.length - 1;
            while (i >= 0 && whitespace.indexOf(str.charAt(i)) !== -1) {
                i--;
            }
            str = str.substring(0, i + 1);
        }
        return str;
    },
    trim: function (s) {
        return DongxwDict.trimRight(DongxwDict.trimLeft(s));
    }
};
Vue.prototype.$dongxwDict = DongxwDict;

export default DongxwDict;
